package com.wind.activity;

import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wind.adapter.ListViewAdapter;
import com.wind.adapter.RecycleViewBaseAdapter;
import com.wind.beans.kindBean;
import com.wind.beans.picManagerBean;
import com.wind.soblogin.HttpManager;
import com.debug.soblogin.R;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class picManageActivity extends AppCompatActivity {


    private RecyclerView mList;
    private ArrayList<kindBean> mData;
    private RecycleViewBaseAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pic_manager);
        //找到控件
        mList = this.findViewById(R.id.k_recycle_view);
        //准备数据
        initData();
        //首次显示先设置一次
//        showList(true, false);



    }

    private void initData() {

        mData = new ArrayList<>();


        HttpManager
                .getSobApi()
                .getPicList()
                .enqueue(new Callback<picManagerBean>() {
                    @Override
                    public void onResponse(Call<picManagerBean> call, Response<picManagerBean> response) {
                        Toast.makeText(picManageActivity.this, "接口响应成功", Toast.LENGTH_LONG).show();
                        picManagerBean data = response.body();


                        for (int i = 0; i < data.getData().getContent().size(); i++) {
                            kindBean kk = new kindBean();
                            kk.url = data.getData().getContent().get(i).getUrl();
                            kk.name= data.getData().getContent().get(i).getUrl();
                            System.out.println("---------->" + kk.url);
                            System.out.println("---------->" + kk.name);
                            mData.add(kk);
                        }
                        LinearLayoutManager layoutManager = new LinearLayoutManager(picManageActivity.this);
                        mList.setLayoutManager(layoutManager);

                        //创建适配器
                        mAdapter = new ListViewAdapter(mData);
                        //设置到recycle里面去
                        mList.setAdapter(mAdapter);


                    }

                    @Override
                    public void onFailure(Call<picManagerBean> call, Throwable t) {
                        Toast.makeText(picManageActivity.this, "失败", Toast.LENGTH_LONG).show();
                        System.out.println("---------->出错了"+call+t);
                    }
                });





    }
}
